package cn.iocoder.yudao.module.wine.dal.mysql.countnameconfig;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.wine.controller.app.supplymarket.vo.AppSupplyMarketPageReqVO;
import cn.iocoder.yudao.module.wine.dal.dataobject.countnameconfig.CountNameConfigDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplytype.SupplyTypeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.admin.countnameconfig.vo.*;

/**
 * 统计名称配置 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CountNameConfigMapper extends BaseMapperX<CountNameConfigDO> {

    default PageResult<CountNameConfigRespVO> selectPage(CountNameConfigPageReqVO reqVO) {
        return selectJoinPage(reqVO, CountNameConfigRespVO.class,new MPJLambdaWrapperX<CountNameConfigDO>()
                .betweenIfPresent(CountNameConfigDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CountNameConfigDO::getGroupNumber, reqVO.getGroupNumber())
                .likeIfPresent(CountNameConfigDO::getCountName, reqVO.getCountName())
                .eqIfPresent(CountNameConfigDO::getFragranceType,reqVO.getFragranceType())//香型
                .eqIfPresent(CountNameConfigDO::getVisible, reqVO.getVisible())
                .eqIfPresent(CountNameConfigDO::getSort, reqVO.getSort())
                .likeIfPresent(CountNameConfigDO::getFailoverName, reqVO.getFailoverName())
                .leftJoin(SupplyTypeDO.class,SupplyTypeDO::getId,CountNameConfigDO::getSupplyTypeId)
                .selectAll(CountNameConfigDO.class)
                .selectAs(SupplyTypeDO::getTypeName,CountNameConfigRespVO::getTypeName)
                //.orderByDesc(CountNameConfigDO::getId));//修改成按排序正排
                .orderByAsc(CountNameConfigDO::getSort));
    }

    default PageResult<CountNameConfigDO> selectByPage(AppSupplyMarketPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CountNameConfigDO>()
                .eqIfPresent(CountNameConfigDO::getVisible, 1)
                .orderByDesc(CountNameConfigDO::getId));
    }

    default PageResult<CountNameConfigRespVO> selectConfigByPage(AppSupplyMarketPageReqVO reqVO) {
        return selectJoinPage(reqVO, CountNameConfigRespVO.class, new MPJLambdaWrapperX<CountNameConfigDO>()
                .eqIfPresent(CountNameConfigDO::getVisible, 1)
                .eqIfPresent(CountNameConfigDO::getFragranceType, reqVO.getFragranceType())
                .eqIfPresent(CountNameConfigDO::getSupplyTypeId, reqVO.getSupplyTypeId())
                .eqIfPresent(CountNameConfigDO::getShowYear, reqVO.getShowYear())
                .eqIfPresent(CountNameConfigDO::getPacking, reqVO.getPacking())
                .orderByAsc(CountNameConfigDO::getSort));
    }

}
